import { Access, useAccess } from '@umijs/max';
import React, { PropsWithChildren } from 'react';

interface PermissionRequiredProps {
  value?: string[];
  fallback?: React.ReactNode;
}

const PermissionRequired: React.FC<
  PropsWithChildren<PermissionRequiredProps>
> = ({ value = [], children, fallback = <></> }) => {
  const access = useAccess();

  return (
    <Access accessible={access.hasPermission(value)} fallback={fallback}>
      {children}
    </Access>
  );
};

export default PermissionRequired;
